/* ----------------------------------------------------------------------------
 *         SAM Software Package License
 * ----------------------------------------------------------------------------
 * Copyright (c) 2015, Atmel Corporation
 *
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * - Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the disclaimer below.
 *
 * Atmel's name may not be used to endorse or promote products derived from
 * this software without specific prior written permission.
 *
 * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
 * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
 * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 * ----------------------------------------------------------------------------
 */

/** \file
 *  USB Audio Speaker & Microphone Function.
 */

/** \addtogroup usbd_audio_speakerphone
 *@{
 *  Implement speaker phone function that combine 1 AC interface, 1 AS interface
 *  for speaker and 1 AS interface for microphone.
 */

#ifndef _AUDD_SPEAKERPHONE_H_
#define _AUDD_SPEAKERPHONE_H_

/*------------------------------------------------------------------------------
 *         Headers
 *------------------------------------------------------------------------------*/

#include <stdint.h>

#include "usb/device/audio/audd_stream.h"
#include "usb/device/usbd_driver.h"
#include "usb/device/usbd.h"

/*------------------------------------------------------------------------------
 *         Defines
 *------------------------------------------------------------------------------*/

/** \addtogroup usbd_audio_ids Audio Device IDs required by driver
 *      @{
 *  The driver uses following fixed entity IDs, use them to define your
 *  descriptor.
 *  \ref AUDD_ID_SpeakerIT
 *  \ref AUDD_ID_SpeakerOT
 *  \ref AUDD_ID_SpeakerFU
 *  \ref AUDD_ID_MicrophoneIT
 *  \ref AUDD_ID_MicrophoneOT
 *  \ref AUDD_ID_MicrophoneFU
 */
/** Speaker input terminal ID */
#define AUDD_ID_SpeakerIT           0x01
/** Speaker output terminal ID */
#define AUDD_ID_SpeakerOT           0x02
/** Speaker feature unit ID */
#define AUDD_ID_SpeakerFU           0x03
/** Microphone input terminal ID */
#define AUDD_ID_MicrophoneIT        0x04
/** Microphone output terminal ID */
#define AUDD_ID_MicrophoneOT        0x05
/** Microphone feature unit ID */
#define AUDD_ID_MicrophoneFU        0x06
/**     @}*/

/** \addtogroup usbd_audio_chs Audio Device Channels
 *      @{
 */
/** Master channel ID */
#define AUDD_CH_Master              0x0
/** Left channel ID */
#define AUDD_CH_L                   0x1
/** Right channel ID */
#define AUDD_CH_R                   0x2
/**     @}*/

/*------------------------------------------------------------------------------
 *         Types
 *------------------------------------------------------------------------------*/

/**
 * Struct of USB Audio Speaker-phone Function, with
 * - 1 control interface for features,
 * - 1 input stream for microphone (Audio IN),
 * - 1 output stream for speaker (Audio OUT).
 */
typedef struct _AUDDSpeakerPhone {
	/** Pointer to AUDDStream Instance */
	AUDDStream *pSpeaker;
	/** Pointer to AUDDStream Instance */
	AUDDStream *pMicrophone;
} AUDDSpeakerPhone;

/*------------------------------------------------------------------------------
 *         Functions
 *------------------------------------------------------------------------------*/

extern void audd_speaker_phone_initializeStream(
	AUDDStream * pAuds,
	uint8_t numChannels,uint16_t wChannelVolumes [ ],
	AUDDStreamEventCallback fCallback,void * pArg);

extern void audd_speaker_phone_initialize(
	AUDDSpeakerPhone * pAudf,
	AUDDStream * pSpeaker,AUDDStream * pMicrophone);

extern const USBGenericDescriptor* audd_speaker_phone_parse_interfaces(
	AUDDSpeakerPhone * pAudf,
	USBGenericDescriptor * pDescriptors,
	uint32_t dwLength);

extern uint32_t audd_speaker_phone_request_handler(
	AUDDSpeakerPhone * pAudf,
	const USBGenericRequest * pRequest);

extern uint32_t audd_speaker_phone_close_stream(
	AUDDSpeakerPhone * pAudf,
	uint32_t bInterface);

extern uint32_t audd_speaker_phone_setup_write(
	AUDDSpeakerPhone * pAudf,
	void * pListInit, uint16_t listSize, uint16_t delaySize,
	usbd_xfer_cb_t callback,void * argument);

extern uint32_t audd_speaker_phone_write(
	AUDDSpeakerPhone * pAudf,
	void * pBuffer,uint16_t wLength);

extern uint32_t audd_speaker_phone_read(
	AUDDSpeakerPhone * pAudf,
	void * pData, uint32_t dwSize,
	usbd_xfer_cb_t fCallback,void * pArg);

/**@}*/
#endif /* _AUDD_SPEAKERPHONE_H_ */

